﻿using System.Windows.Forms;
using DX.ViewModels;
using DX.Views;
using System.Threading.Tasks;

namespace DX
{
    class DefaultCloseStrategy : ICloseStrategy
    {
        public Task<bool> GetCloseAction(IView view, bool? dialogResult = null)
        {
            if (view is Form form)
            {
                form.Close();
                return Task.FromResult(true);
            }
            if (view is UserControl userControl)
            {
                form = userControl.FindForm();
                if (form != null)
                {
                    form.Close();
                    return Task.FromResult(true);
                }
            }
            return Task.FromResult(false);
        }
    }
}
